package ccpv;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import multiarray.MultiArray;

import solver.GradientDescentSolver;
import solver.Results;

import function.ArslanConflictFunction;
import function.ConflictFunction;
import function.SimpleFunc;
import function.TestFunction;

public class TestingGround {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		
      testFunc();
	}
	
	public static void testfunc1() {
		TestFunction testfunc = new TestFunction();
	//	GradientDescentSolver gd = new GradientDescentSolver();
		System.out.println("Ready to solve.");
	//	double[][] values = gd.solver(testfunc);
	}
	
	public static void testFunc() {
		int[] dims = {2,2,2};
		MultiArray<Person> population = new MultiArray<Person>(dims);
		
		int[] c0 = {0,0,0};
		int[] c1 = {0,0,1};
		int[] c2 = {0,1,0};
		int[] c3 = {0,1,1};
		int[] c4 = {1,0,0};
		int[] c5 = {1,0,1};
		int[] c6 = {1,1,0};
		int[] c7 = {1,1,1};
		int q0 = 1;
		int q1 = 1;
		int q2 = 10;
		int q3 = 10;
		int q4 = 10;
		int q5 = 10;
		int q6 = 10;
		int q7 = 10;
		double p0 = 1;
		double p1 = 1;
		double p2 = 1;
		double p3 = 1;
		double p4 = 2.00002;
		double p5 = 2.00003;
		double p6 = 2.00001;
		double p7 = 2.00002;
		
/*		L = 4;
		Pi = [1; 1; 10; 10];
		beta = [0 1 1 1;
		        1 0 1 1;
		        1 1 0 1;
		        1 1 1 0] * 0.0;
		for i = 1:L
		    beta(i,i) = 1;
		end
		c =  1;
		I = 0.5;
		lambda = 0.5;
		epsilon = eps;
		*/

		
		Person per0 = new Person(c0, q0, 0, p0);
		Person per1 = new Person(c1, q1, 0, p1);
		Person per2 = new Person(c2, q2, 0, p2);
		Person per3 = new Person(c3, q3, 0, p3);
		/*Person per4 = new Person(c4, q4, 0, p4);
		Person per5 = new Person(c5, q5, 0, p5);
		Person per6 = new Person(c6, q6, 0, p6);
		Person per7 = new Person(c7, q7, 0, p7);
		*/
		List<List<int[]>> coalitions = new ArrayList<List<int[]>>();
		coalitions.add(new ArrayList<int[]>());
		coalitions.add(new ArrayList<int[]>());
		coalitions.add(new ArrayList<int[]>());
		coalitions.add(new ArrayList<int[]>());
		coalitions.get(0).add(per0.getCharacter());
		coalitions.get(1).add(per1.getCharacter());
		coalitions.get(2).add(per2.getCharacter());
		coalitions.get(3).add(per3.getCharacter());
	/*	coalitions.get(1).add(per4.getCharacter());
	//	coalitions.get(1).add(per5.getCharacter());
		coalitions.get(2).add(per6.getCharacter());
		coalitions.get(2).add(per7.getCharacter());
		*/
		
		/*HashMap<int[],Person> population = new HashMap<int[],Person>();
		population.put(c0, per0);
		population.put(c1, per1);
		population.put(c2, per2);
		population.put(c3, per3);
		population.put(c4, per4);
		population.put(c5, per5);
		population.put(c6, per6);
		population.put(c7, per7);*/
		population.setElementAtIndex(c0,per0);
		population.setElementAtIndex(c1,per1);
		population.setElementAtIndex(c2,per2);
		population.setElementAtIndex(c3,per3);
		/*population.setElementAtIndex(c4,per4);
		population.setElementAtIndex(c5,per5);
		population.setElementAtIndex(c6,per6);
		population.setElementAtIndex(c7,per7);
		*/
		
		RunTimeSettings rt = new RunTimeSettings();
		rt.setC(1);
		rt.setLambda(0.5);
		rt.setI(0.5);
		rt.setF(0.5);
		
		
		HashMap<String,Double> constants = new HashMap<String,Double>();
		constants.put("c", 1.0);
		constants.put("lambda", 0.5);
		constants.put("I", 0.5);
		constants.put("f", 0.5);
		constants.put("minPower", 0.5);
		//float[][] beta = {{1.0f, 1.0f, 1.0f, 1.0f},{1.0f, 1.0f, 1.0f, 1.0f},{1.0f, 1.0f, 1.0f, 1.0f},{1.0f, 1.0f, 1.0f, 1.0f}};
		//float[][] beta = {{1.0f, 0.0f, 0.0f, 0.0f},{0.0f, 1.0f, 0.0f, 0.0f},{0.0f, 0.0f, 1.0f, 0.0f},{0.0f, 0.0f, 0.0f, 1.0f}};
		float[][] beta = {{0.0f, 0.0f, 0.0f, 0.0f},{0.0f, 0.0f, 0.0f, 0.0f},{0.0f, 0.0f, 0.0f, 0.0f},{0.0f, 0.0f, 0.0f, 0.0f}};
		
		ConflictFunction func = new ArslanConflictFunction(population, constants);
		func.setCoalitions(coalitions,beta);
		float[] utils = func.getUtilities(coalitions, beta);
		Results res = func.solve_and_update_agents();
		
		
		
		System.out.println("End Result: 0");
		printMatrix(res.getThetasD());
		
	}
	
	private static void printMatrix(double[][] x) {
		for (int i = 0; i<x.length; i++) {
			System.out.print("[ ");
			for (int j = 0; j<x.length; j++) {
			System.out.print(x[i][j] + " ");
			}
			System.out.println("]");
		}
	}
	
}
